package org.example.demo02;

import jakarta.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@RequestMapping("/response")
@Controller  // 这个是专门返回页面的
public class ResponseController {
    @RequestMapping("returnHtmlPage")
    public String returnHtmlPage() {
        return "/hello.html";
    }

    @ResponseBody
    @RequestMapping("returnDate")
    public String returnDate() {
        return "niubiyyds";
    }
@ResponseBody
@RequestMapping("/returnHtml")
    public String returnHtml(){
        return "<h1>returnHtml</h1>";
}

@ResponseBody
@RequestMapping("/returnJson")
    public User returnJson(){
        User user = new User();
        user.setName("lisi");
        user.setAge(22);
        return user;
}
@ResponseBody
@RequestMapping("/setStatus")
public User setStatus(HttpServletResponse response){
User user = new User();
user.setName("zhangsan");
user.setAge(19);
response.setStatus(500);  //设置状态码
   // System.out.println(response.getStatus());
    return user;
}
@ResponseBody
@RequestMapping(value = "/setHeader",produces = "application/json")
public String setHeader() {
        return "{\"success\":true}";
}
@ResponseBody
@RequestMapping("setHeader2")
public String setHeader2(HttpServletResponse response) {
        response.setHeader("My-Key","myValue");
        return "success";
}
}
